<?php

class Light_Util
{
	public static function arrayMapRecursive($fn, $arr)
	{
        $rarr = array();

        foreach ($arr as $k => $v) {
            $rarr[$k] = is_array($v)
                        ? self::arrayMapRecursive($fn, $v)
                        : $fn($v); // or call_user_func($fn, $v)
        }

        return $rarr;
    }

    public static function merge(array $a, array $b)
    {
        return array_replace_recursive($a, $b);

        foreach ($b as $key => $value) {
            if (array_key_exists($key, $a)) {
                if (is_int($key)) {
                    $a[] = $value;
                } elseif (is_array($value) && is_array($a[$key])) {
                    $a[$key] = static::merge($a[$key], $value);
                } else {
                    $a[$key] = $value;
                }
            } else {
                $a[$key] = $value;
            }
        }

        return $a;
    }
}